home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / SLHCDUMP.C < prev    next >
C/C++ Source or Header  |  1996-09-03  |  3KB  |  117 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "internet.h"
  4. #include "ip.h"
  5. #include "slhc.h"
  6. #include "trace.h"
  7.  
  8. #if !defined(_lint)
  9. static char rcsid[] OPTIONAL = "$Id: slhcdump.c,v 1.10 1996/09/04 01:34:13 root Exp root $";
  10. #endif
  11.  
  12. static int16 decodeint (struct mbuf ** bpp);
  13.  
  14.  
  15. static int16
  16. decodeint (struct mbuf **bpp)
  17. {
  18. char tmpbuf[2];
  19.  
  20.     (void) pullup (bpp, (unsigned char *) tmpbuf, 1);
  21.     if (tmpbuf[0] == 0)
  22.         (void) pullup (bpp, (unsigned char *) tmpbuf, 2);
  23.     else {
  24.         tmpbuf[1] = tmpbuf[0];
  25.         tmpbuf[0] = 0;
  26.     }
  27.     return (get16 (tmpbuf));
  28. }
  29.  
  30.  
  31. void
  32. vjcomp_dump (FILE *fp, struct mbuf **bpp, int unused OPTIONAL)
  33. {
  34. unsigned char changes;
  35. char tmpbuf[2];
  36.  
  37.     if (bpp == NULLBUFP || *bpp == NULLBUF)
  38.         return;
  39.  
  40.     /* Dump compressed TCP/IP header */
  41.     changes = uchar(pullchar (bpp));
  42.     traceprintf (fp, "\tchanges: 0x%02x", changes);
  43.     if (changes & NEW_C) {
  44.         (void) pullup (bpp, (unsigned char *) tmpbuf, 1);
  45.         traceprintf (fp, "   connection: 0x%02x", uchar (tmpbuf[0]));
  46.     }
  47.     (void) pullup (bpp, (unsigned char *) tmpbuf, 2);
  48.     traceprintf (fp, "   TCP checksum: 0x%04x", get16 (tmpbuf));
  49.  
  50.     if (changes & TCP_PUSH_BIT)
  51.         traceprintf (fp, "   PUSH");
  52.     traceprintf (fp, "\n");
  53.  
  54.     switch (changes & SPECIALS_MASK) {
  55.         case SPECIAL_I:
  56.             traceprintf (fp, "\tdelta ACK and delta SEQ implied by length of data\n");
  57.             break;
  58.  
  59.         case SPECIAL_D:
  60.             traceprintf (fp, "\tdelta SEQ implied by length of data\n");
  61.             break;
  62.  
  63.         default:
  64.             if (changes & NEW_U) {
  65.                 traceprintf (fp, "\tUrgent pointer: 0x%02x", decodeint (bpp));
  66.             }
  67.             if (changes & NEW_W)
  68.                 traceprintf (fp, "\tdelta WINDOW: 0x%02x", decodeint (bpp));
  69.             if (changes & NEW_A)
  70.                 traceprintf (fp, "\tdelta ACK: 0x%02x", decodeint (bpp));
  71.             if (changes & NEW_S)
  72.                 traceprintf (fp, "\tdelta SEQ: 0x%02x", decodeint (bpp));
  73.             break;
  74.     };
  75.     if (changes & NEW_I) {
  76.         traceprintf (fp, "\tdelta ID: 0x%02x\n", decodeint (bpp));
  77.     } else {
  78.         traceprintf (fp, "\tincrement ID\n");
  79.     }
  80. }
  81.  
  82.  
  83. /* dump serial line IP packet; may have Van Jacobson TCP header compression */
  84. void
  85. sl_dump (FILE *fp, struct mbuf **bpp, int unused OPTIONAL)
  86. {
  87. struct mbuf *bp, *tbp;
  88. unsigned char c;
  89. int len;
  90.  
  91.     bp = *bpp;
  92.     c = bp->data[0];
  93.     if (c & SL_TYPE_COMPRESSED_TCP) {
  94.         traceprintf (fp, "serial line VJ Compressed TCP: len %3u\n",
  95.                  len_p (*bpp));
  96.         vjcomp_dump (fp, bpp, 0);
  97.     } else if (c >= SL_TYPE_UNCOMPRESSED_TCP) {
  98.         traceprintf (fp, "serial line VJ Uncompressed TCP: len %3u\n",
  99.                  len = len_p (bp));
  100.         /* Get our own copy so we can mess with the data */
  101.         if ((tbp = copy_p (bp, (int16) len)) == NULLBUF)
  102.             return;
  103.  
  104.         traceprintf (fp, "\tconnection ID = %d\n",
  105.                  uchar (tbp->data[9]));    /* FIX THIS! */
  106.         /* Restore the bytes used with Uncompressed TCP */
  107.         tbp->data[0] &= 0x4f;    /* FIX THIS! */
  108.         tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  109.         /* Dump contents as a regular IP packet */
  110.         ip_dump (fp, &tbp, 1);
  111.         free_p (tbp);
  112.     } else {
  113.         traceprintf (fp, "serial line IP: len: %3u\n", len_p (*bpp));
  114.         ip_dump (fp, bpp, 1);
  115.     }
  116. }
  117.